package com.fallsvc.re.javase.string;


import com.fallsvc.re.javase.interfacet.Student;

import java.util.Arrays;

/**
 * @auther falls_vc
 * description:
 * @date 2025/10/13  9:10
 */
public class Demo1 {
    public static void main1(String[] args) {
        String str = "abdefge";
        System.out.println(str.charAt(1));
        System.out.println(str.indexOf('e'));
        System.out.println(str.indexOf('e',4));
        System.out.println(str.indexOf("efg"));
        System.out.println(str.lastIndexOf('e'));

    }

    public static void main2(String[] args) {
        String s1 = String.valueOf(11.11);
        String s2 = String.valueOf(new Student("zhangs",12)); // 调用对象的toString()

        System.out.println(s1);
        System.out.println(s2);

        String str = "hello";
        String s = "HEllo";
        System.out.println(str.toUpperCase());
        System.out.println(s.toLowerCase());

        char[] chars = str.toCharArray();
        for (char ch : chars) {
            System.out.println(ch);
        }

        String x = String.format("%d-%d-%d",2005,04,03);
        System.out.println(x);
//        int a = Integer.valueOf("12");
//        int b = Integer.parseInt("12");
//        System.out.println(a);
//        System.out.println(b);
    }

    public static void main3(String[] args) {
        String t = "I am a boy am!!!";
        System.out.println(t.replaceFirst("am","is"));
//        System.out.println(t.replaceAll("am", "is"));
//        System.out.println(t.replace("am", "is"));
        System.out.println(t);
    }

//    1. 字符"|","*","+"都得加上转义字符，前面加上 "\\" .
//    2. 而如果是 "\" ，那么就得写成 "\\\\" .
//    3. 如果一个字符串中有多个分隔符，可以用"|"作为连字符
    public static void main5(String[] args) {
        String t = "hello world hello bit";
        String[] s = t.split(" ",2); // 分成两段
//        String[] s = t.split(" ");
        for (String x : s) {
            System.out.println(x);
        }

        t = "hello|world|hello&bit";
        String[] split = t.split("\\||&");

        for (String x : split) {
            System.out.println(x);
        }
    }

    public static void main6(String[] args) {
        String t = "  hello world hello bit  ";
        System.out.println(t.substring(12)); //[12,end]
        System.out.println(t.substring(12,17)); // [12,17)

        System.out.println(t);
        System.out.println(t.trim());// 去掉字符串左右两端空格 trim 会去掉字符串开头和结尾的空白字符(空格, 换行, 制表符等)

        String str = " hello%$$%@#$%world 哈哈哈 " ;
//        这两个函数只转换字母
        System.out.println(str.toUpperCase());
        System.out.println(str.toLowerCase());
    }
    public static void main7(String[] args) {
        final int array[] = {1,2,3,4,5};
        array[0] = 100;
        System.out.println(Arrays.toString(array));
        // array = new int[]{4,5,6}; // 编译报错：Error:(19, 9) java: 无法为最终变量array分配值
    }
}
